home *** CD-ROM | disk | FTP | other *** search
/ Teach Your Children: Road Construction Ahead / Teach Your Children: Road Construction Ahead.iso / pc / rca / road.dxr / 00018_Awards Parent.ls < prev    next >
Encoding:
Text File  |  1996-07-17  |  9.6 KB  |  334 lines

  1. property awardsList, roadNameList, firstAwardChannel, roadNameEntry, maxRoadNames, entryX, entryY, firstRoadSlotChan, firstRoadNameChan, trailsSprite, firstLetterBmap, maxCharWidth, maxWidth, maxChars, cursor, cursorCounter, cursorSpeed, onOrOff, roadName, roadOffsets, awardsDataString, dataCounter, roadBitmap, roadBitmapChan, roadSlotVdistance, firstRoadSlotLocV, entrySlot
  2. global gActorList, gHiddenActorList, gUserObject, gMenuObject, gLevelObject, gTruckObject, gSimObject
  3.  
  4. on birth me
  5.   set firstAwardChannel to 9
  6.   set awardsList to ["VTL": 0, "HardHat": 0, "JobSite": 0, "MakeAscene": 0]
  7.   set roadNameList to []
  8.   set roadName to []
  9.   set roadOffsets to [0]
  10.   set roadNameEntry to 0
  11.   set firstRoadSlotChan to 2
  12.   set firstRoadNameChan to 15
  13.   set maxRoadNames to 6
  14.   set firstRoadSlotLocV to 111
  15.   set roadSlotVdistance to 51
  16.   set entryX to 0
  17.   set entryY to 0
  18.   set entrySlot to 0
  19.   set trailsSprite to 13
  20.   set maxCharWidth to 18
  21.   set maxWidth to 143
  22.   set maxChars to 11
  23.   set cursorCounter to 1
  24.   set cursorSpeed to 8
  25.   set onOrOff to 0
  26.   set firstLetterBmap to the number of cast "a2.lower"
  27.   set cursor to firstLetterBmap + 53
  28.   set roadBitmap to the number of cast "roadBitmap"
  29.   set roadBitmapChan to 8
  30.   return me
  31. end
  32.  
  33. on update me
  34.   if roadNameEntry and (count(roadName) = 0) then
  35.     blinkQuestion(me)
  36.   end if
  37. end
  38.  
  39. on predraw me
  40.   repeat with x = 1 to count(awardsList)
  41.     set boolean to getAt(awardsList, x)
  42.     if boolean = 0 then
  43.       set channel to firstAwardChannel + x - 1
  44.       puppetSprite(channel, 1)
  45.       removeSprite(channel)
  46.     end if
  47.   end repeat
  48.   if roadNameEntry = 1 then
  49.     set the locH of sprite roadBitmapChan to 60
  50.     set locV to firstRoadSlotLocV + ((entrySlot - 1) * roadSlotVdistance)
  51.     set the locV of sprite roadBitmapChan to locV
  52.     set the castNum of sprite roadBitmapChan to roadBitmap
  53.     puppetSprite(roadBitmapChan, 1)
  54.   end if
  55. end
  56.  
  57. on cheat me
  58.   setProp(awardsList, "VTL", 1)
  59.   setProp(awardsList, "HardHat", 1)
  60.   setProp(awardsList, "JobSite", 1)
  61.   setProp(awardsList, "MakeAscene", 1)
  62. end
  63.  
  64. on setup me
  65.   clearAllActors()
  66.   add(gActorList, me)
  67.   repeat with x = 1 to count(awardsList)
  68.     set channel to firstAwardChannel + x - 1
  69.     puppetSprite(channel, 1)
  70.   end repeat
  71.   puppetSprite(roadBitmapChan, 1)
  72.   postRoadNames(me)
  73.   if roadNameEntry = 1 then
  74.     repeat with x = 1 to maxChars
  75.       set channel to firstRoadNameChan + x - 1
  76.       puppetSprite(channel, 1)
  77.     end repeat
  78.     set newRoadSlot to firstRoadSlotChan + entrySlot - 1
  79.     set entryX to the left of sprite newRoadSlot + 7
  80.     set entryY to the locV of sprite newRoadSlot
  81.   end if
  82.   if roadNameEntry then
  83.     add(gActorList, birth(script "Rollover Anim Button Class", "returnToSim( gAwardsObject, me )", 27, 27, 5, "B14VO01", "B14RO01"))
  84.   else
  85.     add(gActorList, birth(script "Rollover Anim Button Class", "goMenu( gAwardsObject, me )", 27, 27, 5, "RCA-07VO01", "RCA-07RO01"))
  86.   end if
  87.   add(gActorList, birth(script "Rollover Anim Button Class", "help( gAwardsObject, me )", 28, 28, 11, EMPTY, "RCA-05RO02"))
  88. end
  89.  
  90. on postRoadNames me
  91.   repeat with x = 1 to count(roadNameList)
  92.     if not (roadNameEntry and (x = entrySlot)) then
  93.       set slotSprite to firstRoadSlotChan + x - 1
  94.       set savedNameData to getAt(roadNameList, x)
  95.       set savedName to getAt(savedNameData, 1)
  96.       set savedOffsets to getAt(savedNameData, 2)
  97.       set slotCenter to the locH of sprite slotSprite
  98.       set lastBmap to firstLetterBmap + getAt(savedName, count(savedName)) - 1
  99.       set lastCharWidth to getKernValue(lastBmap)
  100.       set savedNameWidth to getLast(savedOffsets) + 62
  101.       set locH to slotCenter - integer(savedNameWidth / 2)
  102.       set the locV of sprite trailsSprite to the locV of sprite slotSprite
  103.       repeat with letterIndex = 1 to count(savedName)
  104.         set the castNum of sprite trailsSprite to firstLetterBmap + getAt(savedName, letterIndex) - 1
  105.         set the locH of sprite trailsSprite to locH + getAt(savedOffsets, letterIndex)
  106.         updateStage()
  107.       end repeat
  108.       set the locH of sprite trailsSprite to the locH of sprite trailsSprite + lastCharWidth + 7
  109.       set the castNum of sprite trailsSprite to roadBitmap
  110.       updateStage()
  111.     end if
  112.   end repeat
  113.   removeSprite(trailsSprite)
  114. end
  115.  
  116. on addRoadName me
  117.   if roadNameEntry then
  118.     if count(roadName) > 0 then
  119.       setAt(roadNameList, entrySlot, [roadName, roadOffsets])
  120.     else
  121.       setAt(roadNameList, entrySlot, [the userName of gUserObject, the letterHoffsets of gUserObject])
  122.     end if
  123.     set roadName to []
  124.     set roadOffsets to [0]
  125.     set roadNameEntry to 0
  126.   end if
  127. end
  128.  
  129. on simAward me
  130.   set entrySlot to entrySlot + 1
  131.   if entrySlot > maxRoadNames then
  132.     set entrySlot to 1
  133.   end if
  134.   set roadNameEntry to 1
  135. end
  136.  
  137. on giveAward me, awardName
  138.   setProp(awardsList, awardName, 1)
  139. end
  140.  
  141. on enterLetter me, letterNum
  142.   if ((getLast(roadOffsets) + maxCharWidth) <= maxWidth) and (count(roadName) < maxChars) then
  143.     set channel to firstRoadNameChan + count(roadName)
  144.     if count(roadName) = 0 then
  145.       if letterNum = 53 then
  146.         exit
  147.       end if
  148.       set letterNum to letterNum + 26
  149.     end if
  150.     set whichCast to firstLetterBmap + letterNum - 1
  151.     set the castNum of sprite channel to whichCast
  152.     set currentOffset to getLast(roadOffsets)
  153.     set the locH of sprite channel to entryX + currentOffset
  154.     set the locV of sprite channel to entryY
  155.     set letterWidth to getKernValue(whichCast)
  156.     set latestOffset to currentOffset + letterWidth
  157.     add(roadOffsets, latestOffset)
  158.     add(roadName, letterNum)
  159.     set the locH of sprite roadBitmapChan to entryX + latestOffset + 7
  160.     set the locV of sprite roadBitmapChan to entryY
  161.     updateStage()
  162.   else
  163.     beep(1)
  164.   end if
  165. end
  166.  
  167. on eraseLetter me
  168.   if count(roadName) > 0 then
  169.     deleteAt(roadName, count(roadName))
  170.     deleteAt(roadOffsets, count(roadOffsets))
  171.     set the locH of sprite (firstRoadNameChan + count(roadName)) to 1000
  172.     if count(roadName) > 0 then
  173.       set the locH of sprite roadBitmapChan to entryX + getLast(roadOffsets) + 4
  174.     else
  175.       set the locH of sprite roadBitmapChan to 60
  176.     end if
  177.     updateStage()
  178.   else
  179.     beep(1)
  180.   end if
  181. end
  182.  
  183. on blinkQuestion me
  184.   if cursorCounter > cursorSpeed then
  185.     if onOrOff = 0 then
  186.       set the locH of sprite firstRoadNameChan to entryX
  187.       set the locV of sprite firstRoadNameChan to entryY
  188.       set the castNum of sprite firstRoadNameChan to cursor
  189.       set onOrOff to 1
  190.     else
  191.       set the locH of sprite firstRoadNameChan to 1000
  192.       set onOrOff to 0
  193.     end if
  194.     set cursorCounter to 0
  195.   else
  196.     set cursorCounter to cursorCounter + 1
  197.   end if
  198. end
  199.  
  200. on keyHandler me
  201.   set whichKey to the key
  202.   set ascii to charToNum(whichKey)
  203.   if (ascii >= 65) and (ascii <= 90) then
  204.     enterLetter(me, ascii - 64)
  205.   else
  206.     if (ascii >= 97) and (ascii <= 122) then
  207.       enterLetter(me, ascii - 96)
  208.     else
  209.       if ascii = 8 then
  210.         eraseLetter(me)
  211.       else
  212.         if ascii = 45 then
  213.           enterLetter(me, 53)
  214.         end if
  215.       end if
  216.     end if
  217.   end if
  218. end
  219.  
  220. on anyAwards me
  221.   if count(roadNameList) > 0 then
  222.     set flag to 1
  223.   end if
  224.   repeat with boolean in awardsList
  225.     if boolean = 1 then
  226.       set flag to 1
  227.       exit repeat
  228.     end if
  229.   end repeat
  230.   return flag
  231. end
  232.  
  233. on goMenu me, buttonObject
  234.   addRoadName(me)
  235.   clearAllActors()
  236.   unpuppetAll()
  237.   makeButtonJump(buttonObject)
  238.   puppetPalette("AwardsPal")
  239.   go("Grass")
  240.   go(the frame + 1)
  241.   unLoadCast()
  242.   goLocationMap()
  243. end
  244.  
  245. on returnToSim me, buttonObject
  246.   addRoadName(me)
  247.   clearAllActors()
  248.   unpuppetAll()
  249.   makeButtonJump(buttonObject)
  250.   puppetPalette("AwardsPal")
  251.   go("Grass")
  252.   go(the frame + 1)
  253.   puppetPalette("SimPal", 60)
  254.   updateStage()
  255.   puppetPalette(0)
  256.   unLoadCast()
  257.   set the status of gTruckObject to #idle
  258.   set the programmedMove of gTruckObject to 0
  259.   set the obstacleState of gSimObject to EMPTY
  260.   go(label("Simulator" & string(the level of gLevelObject)))
  261. end
  262.  
  263. on saveAwardsData me
  264.   set awardsDataString to EMPTY
  265.   if not anyAwards(me) then
  266.     appendData(me, 0)
  267.   else
  268.     appendData(me, 1)
  269.     set roadCount to count(roadNameList)
  270.     appendData(me, roadCount)
  271.     if roadCount > 0 then
  272.       repeat with roadData in roadNameList
  273.         set bitmapList to getAt(roadData, 1)
  274.         appendData(me, count(bitmapList))
  275.         repeat with bitmap in bitmapList
  276.           appendData(me, bitmap)
  277.         end repeat
  278.         set offsetList to getAt(roadData, 2)
  279.         appendData(me, count(offsetList))
  280.         repeat with offset in offsetList
  281.           appendData(me, offset)
  282.         end repeat
  283.       end repeat
  284.     end if
  285.     repeat with award in awardsList
  286.       appendData(me, award)
  287.     end repeat
  288.   end if
  289.   set awardsData to awardsDataString
  290.   set awardsDataString to EMPTY
  291.   return awardsData
  292. end
  293.  
  294. on loadAwards me, index
  295.   set dataCounter to index
  296.   set anyAwards to readData(me)
  297.   if anyAwards <> 0 then
  298.     set howManyRoads to readData(me)
  299.     if howManyRoads > 0 then
  300.       repeat with x = 1 to howManyRoads
  301.         set bitmapList to []
  302.         set howManyBitmaps to readData(me)
  303.         repeat with y = 1 to howManyBitmaps
  304.           add(bitmapList, readData(me))
  305.         end repeat
  306.         set offsetList to []
  307.         set howManyOffsets to readData(me)
  308.         repeat with y = 1 to howManyOffsets
  309.           add(offsetList, readData(me))
  310.         end repeat
  311.         add(roadNameList, [bitmapList, offsetList])
  312.       end repeat
  313.     end if
  314.     repeat with x = 1 to count(awardsList)
  315.       setAt(awardsList, x, readData(me))
  316.     end repeat
  317.   end if
  318.   return dataCounter
  319. end
  320.  
  321. on appendData me, datum
  322.   set awardsDataString to awardsDataString & string(datum) & ","
  323. end
  324.  
  325. on readData me
  326.   set datum to value(item dataCounter of the dataString of gMenuObject)
  327.   set dataCounter to dataCounter + 1
  328.   return datum
  329. end
  330.  
  331. on help me, buttonObject
  332.   birth(script "Help Parent", buttonObject, #Awards)
  333. end
  334.